package com.bookcode;

import com.bookcode.dao.ActorRepository;
import com.bookcode.entity.Actor;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.boot.CommandLineRunner;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.context.annotation.Bean;
import org.springframework.data.neo4j.repository.config.EnableNeo4jRepositories;
import org.springframework.transaction.annotation.EnableTransactionManagement;

import java.util.Arrays;
import java.util.List;
@EnableTransactionManagement
@EnableNeo4jRepositories
@SpringBootApplication
public class DemoApplication {
   // private final static Logger log = LoggerFactory.getLogger(DemoApplication.class);

    public static void main(String[] args) {
        SpringApplication.run(DemoApplication.class, args);
    }
   /* @Bean
    CommandLineRunner demo(ActorRepository repository) {
        return args -> {
            repository.deleteAll();           //辅助工作，删除所有信息
            Actor greg = new Actor("Greg");
            Actor roy = new Actor("Roy");
            Actor craig = new Actor("Craig");
            List<Actor> team = Arrays.asList(greg, roy, craig);
            log.info("Before linking up with Neo4j...");
            team.stream().forEach(Actor -> log.info("\t" + Actor.toString()));
            repository.save(greg);
            repository.save(roy);
            repository.save(craig);
            greg = repository.findByName(greg.getName());
            greg.worksWith(roy);
            greg.worksWith(craig);
            repository.save(greg);
            roy =repository.findByName(roy.getName());
            roy.worksWith(craig);
            repository.save(roy);
            log.info("Lookup each Actor by name...");
            team.stream().forEach(Actor -> log.info(
                    "\t" + repository.findByName(Actor.getName()).toString()));
        };
    }*/
}
